/**
 * vargs_func.c
 * variable arguments functions.
 * @author: zt 2013-10-14
 */
#include<stdio.h>
#include<stdlib.h>
#include<stdarg.h>
#include<assert.h>

void vargs_printf(int x, char* format, ...)
{	
	int i;
	va_list vaList;
	
	//va_start(vaList, x);  // error.16 second parameter of `va_start' not last named argument 
	//printf("%s", va_arg(vaList, char*));
	va_start(vaList, format);
	for(i = 0; format[i] != '\0'; i++) {
		switch(format[i]) {
			case 's':
				printf("%s", va_arg(vaList, char*));
				break;
			case 'd':	
				printf("%d", va_arg(vaList, int));
				break;
			default:
				assert(0);
		}
	}
	va_end(vaList);
	putchar('\n');
	return ;	
}

int main(void)
{
	vargs_printf(123, "sd", "test", 123); 
	getchar();
	return 0;	
}
